package controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.DBHelper;
import model.User;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import form.RegistrationForm;

public class RegisterAction1 extends Action {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		RegistrationForm registrationForm = (RegistrationForm) form;

		List<User> userList = DBHelper.getUserList();

		User user = DBHelper.createInstance(registrationForm, userList.size());

		userList.add(user);

		HttpSession session = request.getSession();

		session.setAttribute("newUser", Boolean.TRUE);
		
		// DBHelper.testHibernate((SessionFactory)request.getServletContext().getAttribute(MyHibernatePlugIn.KEY_NAME));

		return mapping.findForward("success");
	}
}
